package com.hknc.btscale.view;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hknc.btscale.MainActivity;
import com.hknc.btscale.R;
import com.hknc.btscale.adapter.GoodsAdapter;
import com.hknc.btscale.bean.SaveGoods;

import java.util.ArrayList;
import java.util.List;

public class BannerFragmentRv extends Fragment {
    private static final String POSITION = "position";

    public static BannerFragmentRv newInstance(int position, List<SaveGoods> list) {
        ArrayList list1 = new ArrayList();
        list1.addAll(list);
        BannerFragmentRv fragment = new BannerFragmentRv();
        Bundle args = new Bundle();
        args.putCharSequenceArrayList("rv", list1);
        args.putInt(POSITION, position);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ArrayList list = getArguments().getCharSequenceArrayList("rv");
        ArrayList<SaveGoods> list1 = new ArrayList<>();
        list1.addAll(list);
        //recyclerview
        View viewRv = inflater.inflate(R.layout.recyclerviewmain, container, false);
        RecyclerView recyclerView = viewRv.findViewById(R.id.recyclerview1);
        GridLayoutManager manager = new GridLayoutManager(getContext(), 5);
        GoodsAdapter adapter = new GoodsAdapter(getContext(), R.layout.item_goodsmain);
        adapter.setGoodsBeans(list1);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
        return viewRv;
    }
}